const std = @import("std");
const t = std.testing;

fn isDigit(x: u8) bool {
    return '0' <= x and x <= '9';
}
fn part1(data: []const u8) !i32 {
    var iter = std.mem.tokenize(u8, data, "\n");
    var res: i32 = 0;
    while (iter.next()) |line| {
        var first: i32 = -1;
        var last: i32 = -1;
        for (line) |char| {
            if (isDigit(char)) {
                last = char - 48;
                if (first == -1) {
                    first = char - 48;
                }
            }
        }
        res += first * 10 + last;
    }
    return res;
}

const Digit = struct {
    pattern: []const u8,
    value: i32,
};
const digits = [_]Digit{
    .{ .pattern = "1", .value = 1 },
    .{ .pattern = "2", .value = 2 },
    .{ .pattern = "3", .value = 3 },
    .{ .pattern = "4", .value = 4 },
    .{ .pattern = "5", .value = 5 },
    .{ .pattern = "6", .value = 6 },
    .{ .pattern = "7", .value = 7 },
    .{ .pattern = "8", .value = 8 },
    .{ .pattern = "9", .value = 9 },
};
const letters = [_]Digit{
    .{ .pattern = "one", .value = 1 },
    .{ .pattern = "two", .value = 2 },
    .{ .pattern = "three", .value = 3 },
    .{ .pattern = "four", .value = 4 },
    .{ .pattern = "five", .value = 5 },
    .{ .pattern = "six", .value = 6 },
    .{ .pattern = "seven", .value = 7 },
    .{ .pattern = "eight", .value = 8 },
    .{ .pattern = "nine", .value = 9 },
};
const all = digits ++ letters;

fn part2(data: []const u8) !i32 {
    var iter = std.mem.tokenize(u8, data, "\n");
    var res:i32 = 0;
    while(iter.next()) |line|{
        var first:i32 = -1;
        var last:i32 = -1;
        
    }
}

test "part 1 test" {
    const input =
        \\ 1abc2
        \\ pqr3stu8vwx
        \\ a1b2c3d4e5f
        \\ treb7uchet
    ;

    const actual = try part1(input);
    try t.expectEqual(142, actual);
}

test "part 2 test" {
    const input =
        \\two1nine
        \\eightwothree
        \\abcone2threexyz
        \\xtwone3four
        \\4nineeightseven2
        \\zoneight234
        \\7pqrstsixteen
    ;
    const actual = try part2(input);
    try t.expectEqual(281, actual);
}
